using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Sigecov.Models.Mapping
{
    public class FornecedoreMap : EntityTypeConfiguration<Fornecedore>
    {
        public FornecedoreMap()
        {
            // Primary Key
            this.HasKey(t => t.forId);

            // Properties
            this.Property(t => t.forEmpresa)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.forContato)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.forCargoContato)
                .IsRequired()
                .HasMaxLength(30);

            this.Property(t => t.forTipoLogradouro)
                .HasMaxLength(30);

            this.Property(t => t.forLogradouro)
                .IsRequired()
                .HasMaxLength(60);

            this.Property(t => t.forBairro)
                .IsRequired()
                .HasMaxLength(30);

            this.Property(t => t.forComplemento)
                .HasMaxLength(50);

            this.Property(t => t.forCep)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.forTelefone)
                .IsRequired()
                .HasMaxLength(14);

            this.Property(t => t.forFax)
                .HasMaxLength(14);

            this.Property(t => t.forHomePage)
                .HasMaxLength(80);

            this.Property(t => t.forStatus)
                .IsRequired()
                .HasMaxLength(1);

            // Table & Column Mappings
            this.ToTable("Fornecedores");
            this.Property(t => t.forId).HasColumnName("forId");
            this.Property(t => t.forEmpresa).HasColumnName("forEmpresa");
            this.Property(t => t.forContato).HasColumnName("forContato");
            this.Property(t => t.forCargoContato).HasColumnName("forCargoContato");
            this.Property(t => t.forTipoLogradouro).HasColumnName("forTipoLogradouro");
            this.Property(t => t.forLogradouro).HasColumnName("forLogradouro");
            this.Property(t => t.forNumero).HasColumnName("forNumero");
            this.Property(t => t.forBairro).HasColumnName("forBairro");
            this.Property(t => t.forComplemento).HasColumnName("forComplemento");
            this.Property(t => t.forCep).HasColumnName("forCep");
            this.Property(t => t.cidId).HasColumnName("cidId");
            this.Property(t => t.forTelefone).HasColumnName("forTelefone");
            this.Property(t => t.forFax).HasColumnName("forFax");
            this.Property(t => t.forHomePage).HasColumnName("forHomePage");
            this.Property(t => t.forStatus).HasColumnName("forStatus");

            // Relationships
            this.HasRequired(t => t.Cidade)
                .WithMany(t => t.Fornecedores)
                .HasForeignKey(d => d.cidId);

        }
    }
}
